import java.util.Arrays;

public class Test2 {
    public static void insetSort(int[] array) {
        for (int i = 1; i < array.length ; i++) {
            int j = i-1;
            int tmp=array[i];
            for (; j >=0; j--) {
                if(array[j]>tmp){
                    array[j+1]=array[j];
                }else {
                    array[j+1]=tmp;
                    break;
                }
            }
            array[j+1]=tmp;
        }
    }
    public static void shellSort(int[] arr){
        int gap=arr.length;
        while (gap>1){
            gap/=2;
            shell(arr,gap);
        }
    }

    private static void shell(int[] arr, int gap) {
        for (int i = gap; i < arr.length; i++) {
            int tmp=arr[i];
            int j=i-gap;
            for (; j >=0; j-=gap) {
                if(arr[j]>tmp){
                    arr[j+gap]=arr[j];
                }else {
                    arr[j+gap]=tmp;
                    break;
                }
            }
            arr[j+gap]=tmp;
        }
    }

    public static void main(String[] args) {
        int[] arr ={12,2,5,7,3};
        int[] arr2=Arrays.copyOf(arr,arr.length);
        System.out.println(Arrays.toString(arr));
        insetSort(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(arr2));
        shellSort(arr2);
        System.out.println(Arrays.toString(arr2));
    }

}
